package com.blog.config;

import com.blog.properties.QiniuOssProperties;
import com.blog.utils.QiniuOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfiguration {
    //注入一个七牛云的工具类的Bean
    @Bean
    @ConditionalOnMissingBean //保证只创建一个Bean
    public QiniuOssUtil qiniuOssUtil(QiniuOssProperties qiniuOssProperties) {
        log.info("开始创建七牛云文件上传工具类对象；{}", qiniuOssProperties);
        return new QiniuOssUtil(qiniuOssProperties.getAccessKey(),
                                qiniuOssProperties.getSecretKey(),
                                qiniuOssProperties.getBucketName());
    }
}
